
package com.seekting.study;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HostTest {

    public static final String HOST_PATTERN = "(?<=\\.)[^.]*\\.[^.]*$";
    public static final String OLD_HOST_PATTERN = "(?<=//|)((\\w)+\\.)+\\w+";

    public static void main(String[] args) {

        long time = TimeUnit.HOURS.toMillis(1);
        System.out.println(time == 1000 * 60 * 60);
        getHost("http://www.baidu.com");
        getHost("http://3g.sina.com");
        getHost("http://2014.sina.com");
        getHost("http://qq.com/?pgv_ref=aio2012&ptlang=2052");
    }

    public static void getHost(String str) {
        URL url;
        try {
            url = new URL(str);
            System.out.println(url.getHost());
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static boolean isSameHost(String url) {
        Pattern p = Pattern.compile(OLD_HOST_PATTERN, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(url);
        if (m.find()) {
            String host = m.group();
            System.out.println(host);
        }
        return false;
    }
}
